package com.wxtech.heartbeat.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
//import java.util.Calendar;
import java.util.Date;

//import org.apache.log4j.Logger;

//import com.wxtech.heartbeat.server.protocol.DataCollectProtocolDecoder;

public class DateUtil {
	
	//把一个6位字节组成的二进制转成一个Date
	//6位字节分别代表年、月、日、时、分、秒
	public static Date parseDateTime(byte[] dateBytes) {
		if (dateBytes == null || dateBytes.length != 6) {
			return null;
		}
		
		//Calendar cal = Calendar.getInstance();
		int year = new Integer(dateBytes[0]);// +2000
		int mon = new Integer(dateBytes[1]); //1-12
		int day = new Integer(dateBytes[2]);
		int hour = new Integer(dateBytes[3]);
		int min = new Integer(dateBytes[4]);
		int sec = new Integer(dateBytes[5]);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
		Date d = null;
		try {
			d = sdf.parse("" + (year + 2000) + "-" + mon  + "-" + day + " " + hour + "-" + min + "-" + sec);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			//e.printStackTrace();
		}
		//cal.set(year, mon, day, hour, min, sec);
		return d;
	}
}
